<template>
    <div>
        <van-nav-bar title="" left-text="返回" left-arrow @click-left="() => { $router.push('/home/user') }" />
        <van-search v-model="value" shape="round" background="#4fc08d" placeholder="请输入搜索关键词" />

        <van-cell-group v-for="item in qsearch" v-if="sta">
            <router-link :to="'/xq/'+item.goods_id">
                <van-cell :title="item.goods_name" />
            </router-link>

        </van-cell-group>

        <van-empty image="https://fastly.jsdelivr.net/npm/@vant/assets/custom-empty-image.png" image-size="80"
            description="暂无信息" v-else />
    </div>
</template>

<script setup>
import { ref, watch } from 'vue';
let sta = ref(false)
let value = ref('')
let qsearch = ref([])
import _ from 'lodash'
import { qsearchApi } from '@/api/api';


watch(value, _.debounce((val) => {
    // console.log('监听', res);
    qsearchApi(val).then(res => {
        console.log('搜索', res);
        qsearch.value = res.data.message
        if (res.data.message!= null) {
            sta.value = true
        }
        else {
            sta.value = false
        }
    })
}, 1000))

</script>

<style lang="scss" scoped></style>